
#Goal for this example:
# Show how you can import a collection of ptx files as an IMPORTED OBJECT
#  target
# Show how once you have an IMPORTED OBJECT target you can embed those
# ptx files/ objects into a library

#Including this so I can easily get the paths to the cuda library ( CUDA_LIBRARIES )
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CUDAExamples_SOURCE_DIR}/cmake")
find_package(CUDAWrapper)

# Create imported target ImportedPTXObjects
add_library(ImportedPTXObjects OBJECT IMPORTED)
set_property(TARGET CudaPTXObjects APPEND PROPERTY IMPORTED_CONFIGURATIONS RELEASE DEBUG)
set_target_properties(ImportedPTXObjects PROPERTIES
  IMPORTED_OBJECTS_RELEASE "${CMAKE_CURRENT_SOURCE_DIR}/kernelA.ptx;${CMAKE_CURRENT_SOURCE_DIR}/kernelB.ptx;"
  IMPORTED_OBJECTS_DEBUG "${CMAKE_CURRENT_SOURCE_DIR}/kernelA.ptx;${CMAKE_CURRENT_SOURCE_DIR}/kernelC.ptx;"
  IMPORTED_OBJECTS "${CMAKE_CURRENT_SOURCE_DIR}/kernelA.ptx;${CMAKE_CURRENT_SOURCE_DIR}/kernelB.ptx;${CMAKE_CURRENT_SOURCE_DIR}/kernelC.ptx;"
  )

#We need to pass the collection of PTX files down to the importer in some
#manner.
# Our options are:
# 1. Generate a file with the content being the ptx file paths


set(output_file ${CMAKE_CURRENT_BINARY_DIR}/ptx_file_locations.h)
file(GENERATE OUTPUT ${output_file}
     CONTENT [[

#include <vector>
#include <string>

#ifndef ptx_file_locations_h
#define ptx_file_locations_h

static std::string ptx_paths = "$<TARGET_OBJECTS:ImportedPTXObjects>";

#endif

]]
)

#
add_executable(ConsumeImportedPTX importer.cpp)

#need to make sure we can find the ptx_file_locations header
target_include_directories(ConsumeImportedPTX PRIVATE ${CMAKE_CURRENT_BINARY_DIR})

#make sure we are linked against cuda and have the proper include paths
target_include_directories(ConsumeImportedPTX PRIVATE ${CMAKE_CUDA_TOOLKIT_INCLUDE_DIRECTORIES})
target_link_libraries(ConsumeImportedPTX PRIVATE ${CUDA_LIBRARIES})




